package com.flink.hbase.kafka2elasticsearch;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 用户文档 Bean，用于 Elasticsearch 索引
 */
public class UserDocument implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @JsonProperty("user_id")
    private String userId;
    
    @JsonProperty("name")
    private String name;
    
    @JsonProperty("age")
    private Integer age;
    
    @JsonProperty("gender")
    private String gender;
    
    @JsonProperty("email")
    private String email;
    
    @JsonProperty("phone")
    private String phone;
    
    @JsonProperty("address")
    private String address;
    
    @JsonProperty("city")
    private String city;
    
    @JsonProperty("country")
    private String country;
    
    @JsonProperty("registration_date")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime registrationDate;
    
    @JsonProperty("last_login")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime lastLogin;
    
    @JsonProperty("status")
    private String status;
    
    @JsonProperty("tags")
    private String tags;
    
    @JsonProperty("score")
    private Double score;
    
    @JsonProperty("create_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;
    
    @JsonProperty("update_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;
    
    // 默认构造函数
    public UserDocument() {
    }
    
    // 全参构造函数
    public UserDocument(String userId, String name, Integer age, String gender, String email, 
                       String phone, String address, String city, String country, 
                       LocalDateTime registrationDate, LocalDateTime lastLogin, String status, 
                       String tags, Double score, LocalDateTime createTime, LocalDateTime updateTime) {
        this.userId = userId;
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.email = email;
        this.phone = phone;
        this.address = address;
        this.city = city;
        this.country = country;
        this.registrationDate = registrationDate;
        this.lastLogin = lastLogin;
        this.status = status;
        this.tags = tags;
        this.score = score;
        this.createTime = createTime;
        this.updateTime = updateTime;
    }
    
    // Getter 和 Setter 方法
    public String getUserId() {
        return userId;
    }
    
    public void setUserId(String userId) {
        this.userId = userId;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public Integer getAge() {
        return age;
    }
    
    public void setAge(Integer age) {
        this.age = age;
    }
    
    public String getGender() {
        return gender;
    }
    
    public void setGender(String gender) {
        this.gender = gender;
    }
    
    public String getEmail() {
        return email;
    }
    
    public void setEmail(String email) {
        this.email = email;
    }
    
    public String getPhone() {
        return phone;
    }
    
    public void setPhone(String phone) {
        this.phone = phone;
    }
    
    public String getAddress() {
        return address;
    }
    
    public void setAddress(String address) {
        this.address = address;
    }
    
    public String getCity() {
        return city;
    }
    
    public void setCity(String city) {
        this.city = city;
    }
    
    public String getCountry() {
        return country;
    }
    
    public void setCountry(String country) {
        this.country = country;
    }
    
    public LocalDateTime getRegistrationDate() {
        return registrationDate;
    }
    
    public void setRegistrationDate(LocalDateTime registrationDate) {
        this.registrationDate = registrationDate;
    }
    
    public LocalDateTime getLastLogin() {
        return lastLogin;
    }
    
    public void setLastLogin(LocalDateTime lastLogin) {
        this.lastLogin = lastLogin;
    }
    
    public String getStatus() {
        return status;
    }
    
    public void setStatus(String status) {
        this.status = status;
    }
    
    public String getTags() {
        return tags;
    }
    
    public void setTags(String tags) {
        this.tags = tags;
    }
    
    public Double getScore() {
        return score;
    }
    
    public void setScore(Double score) {
        this.score = score;
    }
    
    public LocalDateTime getCreateTime() {
        return createTime;
    }
    
    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }
    
    public LocalDateTime getUpdateTime() {
        return updateTime;
    }
    
    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        UserDocument that = (UserDocument) o;
        return Objects.equals(userId, that.userId);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(userId);
    }
    
    @Override
    public String toString() {
        return "UserDocument{" +
                "userId='" + userId + '\'' +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", gender='" + gender + '\'' +
                ", email='" + email + '\'' +
                ", phone='" + phone + '\'' +
                ", address='" + address + '\'' +
                ", city='" + city + '\'' +
                ", country='" + country + '\'' +
                ", registrationDate=" + registrationDate +
                ", lastLogin=" + lastLogin +
                ", status='" + status + '\'' +
                ", tags='" + tags + '\'' +
                ", score=" + score +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                '}';
    }
    
    /**
     * 获取用于 Elasticsearch 的文档 ID
     */
    public String getDocumentId() {
        return userId;
    }
    
    /**
     * 验证文档数据是否有效
     */
    public boolean isValid() {
        return userId != null && !userId.trim().isEmpty() 
            && name != null && !name.trim().isEmpty();
    }
    
    /**
     * 构建器模式
     */
    public static class Builder {
        private UserDocument document = new UserDocument();
        
        public Builder userId(String userId) {
            document.setUserId(userId);
            return this;
        }
        
        public Builder name(String name) {
            document.setName(name);
            return this;
        }
        
        public Builder age(Integer age) {
            document.setAge(age);
            return this;
        }
        
        public Builder gender(String gender) {
            document.setGender(gender);
            return this;
        }
        
        public Builder email(String email) {
            document.setEmail(email);
            return this;
        }
        
        public Builder phone(String phone) {
            document.setPhone(phone);
            return this;
        }
        
        public Builder address(String address) {
            document.setAddress(address);
            return this;
        }
        
        public Builder city(String city) {
            document.setCity(city);
            return this;
        }
        
        public Builder country(String country) {
            document.setCountry(country);
            return this;
        }
        
        public Builder registrationDate(LocalDateTime registrationDate) {
            document.setRegistrationDate(registrationDate);
            return this;
        }
        
        public Builder lastLogin(LocalDateTime lastLogin) {
            document.setLastLogin(lastLogin);
            return this;
        }
        
        public Builder status(String status) {
            document.setStatus(status);
            return this;
        }
        
        public Builder tags(String tags) {
            document.setTags(tags);
            return this;
        }
        
        public Builder score(Double score) {
            document.setScore(score);
            return this;
        }
        
        public Builder createTime(LocalDateTime createTime) {
            document.setCreateTime(createTime);
            return this;
        }
        
        public Builder updateTime(LocalDateTime updateTime) {
            document.setUpdateTime(updateTime);
            return this;
        }
        
        public UserDocument build() {
            return document;
        }
    }
    
    public static Builder builder() {
        return new Builder();
    }
} 